/**
 * TypeScript文件示例
 * TypeScript文件默认具有类型安全性
 */

interface Product {
  id: number;
  name: string;
  price: number;
  category: string;
}

class ProductService {
  private products: Product[] = [];

  addProduct(product: Product): void {
    this.products.push(product);
  }

  getProduct(id: number): Product | undefined {
    return this.products.find(p => p.id === id);
  }

  getProductsByCategory(category: string): Product[] {
    return this.products.filter(p => p.category === category);
  }

  getTotalValue(): number {
    return this.products.reduce((total, product) => total + product.price, 0);
  }
}

export type { Product };
export { ProductService }; 